import ObjectId from "bson-objectid";

function stringToObjectId(idString: string): ObjectId | null {
  try {
    // Check if the string is a valid ObjectId
    if (!ObjectId.isValid(idString)) {
      console.error("Invalid ObjectId string:", idString);
      return null; // Or throw an error, depending on your use case
    }

    const objectId = new ObjectId(idString);
    return objectId;
  } catch (error) {
    console.error("Error converting string to ObjectId:", error);
    return null; // Or throw an error
  }
}

export {stringToObjectId} ;
